﻿<script type="text/javascript">
    function initcombo() {
        //取修理类别
        $("#RepairType").combobox({
            url: '@Url.Content("~/CM/Refuel/GetRepairType/")',
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            prompt: "--请选择--"
        });

        //选择车牌号码取出对应的车辆编号和车辆编码和所属分中心，分站
        $("#ActualCode").combobox({
            url: '@Url.Content("~/CM/Refuel/GetActualCode?em=")' + '@ViewData["em"]' + '&selfCenterID=' + '@ViewData["selfCenterID"]' + '&selfStationID=' + '@ViewData["selfStationID"]' + '&selfWorkCode=' + '@ViewData["selfWorkCode"]',
            valueField: 'Name',
            textField: 'Name',
            editable: true,
            prompt: '--请选择--',
            filter: function (q, row) {
                var opts = $('#ActualCode').combobox('options');
                return row[opts.textField].indexOf(q) > -1;
            },
            onSelect: function (rec) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Content("~/CM/Refuel/GetListByActualCode")',
                    data:
                        {
                            actualCode: rec.Name
                        },
                    dataType: "json",
                    success: function (jsData) {
                        $('#AmbulanceNumber').combobox('setText', jsData.model.AmbulanceNumber);
                        $('#AmbulanceCode').val(jsData.model.AmbulanceCode);
                        $('#CenterID').val(jsData.model.CenterID);
                        $('#StationID').val(jsData.model.StationID);
                    }
                });
            },
            onChange: function () {
                $('#AmbulanceNumber').combobox('clear');
            }
        });
        //选择车辆编号取出对应的车牌号码和车辆编码和所属分中心，分站
        $("#AmbulanceNumber").combobox({
            url: '@Url.Content("~/CM/Refuel/GetAmbulanceNumber?em=")' + '@ViewData["em"]' + '&selfCenterID=' + '@ViewData["selfCenterID"]' + '&selfStationID=' + '@ViewData["selfStationID"]' + '&selfWorkCode=' + '@ViewData["selfWorkCode"]',
            valueField: 'Name',
            textField: 'Name',
            editable: true,
            prompt: '--请选择--',
            filter: function (q, row) {
                var opts = $('#AmbulanceNumber').combobox('options');
                return row[opts.textField].indexOf(q) > -1;
            },
            onSelect: function (rec) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Content("~/CM/Refuel/GetListByAmbulanceNumber")',
                    data:
                        {
                            ambulanceNumber: rec.Name
                        },
                    dataType: "json",
                    success: function (jsData) {
                        $('#ActualCode').combobox('setText', jsData.model.ActualCode);
                        $('#AmbulanceCode').val(jsData.model.AmbulanceCode);
                        $('#CenterID').val(jsData.model.CenterID);
                        $('#StationID').val(jsData.model.StationID);
                    }
                });
            },
            onChange: function () {
                $('#ActualCode').combobox('clear');
            }
        });
        //送保日期不能超过当前日期
        $("#SendConfirmedTime").datetimebox({
            onChange: function () {
                var t1 = $("#SendConfirmedTime").datetimebox("getValue");
                t1 = t1.replace(/-/g, "/");
                var da = new Date(t1);
                var MM = da.getMonth() < 9 ? "0" + (parseInt(da.getMonth()) + 1) : (parseInt(da.getMonth()) + 1);
                var dd = da.getDate() < 10 ? "0" + da.getDate() : da.getDate();
                var hh = da.getHours() < 10 ? "0" + da.getHours() : da.getHours();
                var mm = da.getMinutes() < 10 ? "0" + da.getMinutes() : da.getMinutes();
                var ss = da.getSeconds() < 10 ? "0" + da.getSeconds() : da.getSeconds();
                var t3 = da.getFullYear() + "-" + MM + "-" + dd + "  " + hh + ":" + mm + ":" + ss;


                var t2 = $.GetToday();
                if (t3 > t2) {
                    $.messager.alert('提示', '送保日期超过当前时间，请重新填写', 'info', function () {
                        $('#SendConfirmedTime').datetimebox('clear');
                    });
                }
            }
        });
        //竣工日期不能超过当前日期
        $("#CompletionTime").datetimebox({
            onChange: function () {
                var t1 = $("#CompletionTime").datetimebox("getValue");
                t1 = t1.replace(/-/g, "/");
                var da = new Date(t1);
                var MM = da.getMonth() < 9 ? "0" + (parseInt(da.getMonth()) + 1) : (parseInt(da.getMonth()) + 1);
                var dd = da.getDate() < 10 ? "0" + da.getDate() : da.getDate();
                var hh = da.getHours() < 10 ? "0" + da.getHours() : da.getHours();
                var mm = da.getMinutes() < 10 ? "0" + da.getMinutes() : da.getMinutes();
                var ss = da.getSeconds() < 10 ? "0" + da.getSeconds() : da.getSeconds();
                var t3 = da.getFullYear() + "-" + MM + "-" + dd + "  " + hh + ":" + mm + ":" + ss;


                var t2 = $.GetToday();
                if (t3 > t2) {
                    $.messager.alert('提示', '竣工日期超过当前时间，请重新填写', 'info', function () {
                        $('#CompletionTime').datetimebox('clear');
                    });
                }
            }
        });
    }

    //新增提交方法
    function submitAddForm() {
        var isValid = $("#NewRepairMaintainList").form("validate");
        if (isValid) {
            //var x = $('#InMileage').numberbox('getText');
            //var y = $('#OutMileage').numberbox('getText');
            //if (parseFloat(y) - parseFloat(x) < 0) {
            //    $.messager.alert('提示', '出厂里程表数小于进厂里程表数，请重新确认后再填写', 'info', function () {
            //    });
            //}
            //var x = $('#InOilMass').numberbox('getText');
            //var y = $('#OutOilMass').numberbox('getText');
            //if (parseFloat(y) - parseFloat(x) > 0) {
            //    $.messager.alert('提示', '出厂油量大于进厂油量，请重新确认后再填写', 'info', function () {
            //    });
            //}
            //$('#btnadd').linkbutton('disable');
            $.messager.confirm('提示', '确认新增此整修保养信息吗?', function (r) {
                if (r) {
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/CM/RepairMaintain/RepairMaintainAdd")',
                        data:
                            {
                                sRepairInfo: JSON.stringify(RepairModel(false))
                            },
                        dataType: "json",
                        success: function (jsData) {
                            $.handleJsonResult(jsData, function () {
                                $('#NewRepairMaintainList').dialog("close");
                                $("#gridRepair").datagrid("reload");
                            }, function () {
                                $('#btnadd').linkbutton('enable');
                            });
                        }
                    });
                } else { $('#btnadd').linkbutton('enable'); }
            });
        } else {
            $.showMsg("请填写必填项！", "提示");
        }
    }
    //修改提交方法
    function submitEditForm() {
        var isValid = $("#NewRepairMaintainList").form("validate");
        if (isValid) {
            //var x = $('#InMileage').numberbox('getText');
            //var y = $('#OutMileage').numberbox('getText');
            //if (parseFloat(y) - parseFloat(x) < 0) {
            //    $.messager.alert('提示', '出厂里程表数小于进厂里程表数，请重新确认后再填写', 'info', function () {
            //    });
            //}
            //var x = $('#InOilMass').numberbox('getText');
            //var y = $('#OutOilMass').numberbox('getText');
            //if (parseFloat(y) - parseFloat(x) > 0) {
            //    $.messager.alert('提示', '出厂油量大于进厂油量，请重新确认后再填写', 'info', function () {
            //    });
            //}
            $.messager.confirm('提示', '确认修改该数据吗?', function (r) {
                if (r) {
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/CM/RepairMaintain/RepairMaintainEdit")',
                        data:
                            {
                                sRepairInfo: JSON.stringify(RepairModel(true))
                            },
                        dataType: "json",
                        success: function (jsData) {
                            $.handleJsonResult(jsData, function () {
                                $('#NewRepairMaintainList').dialog("close");
                                $("#gridRepair").datagrid("reload");
                            });
                        }
                    });
                } else { $('#btnadd').linkbutton('enable'); }
            });
        } else {
            $.showMsg("请填写必填项！", "提示");
        }
    }

    //获取填写所有值
    function RepairModel(isEdit) {
        var obj = new Object();
        if (isEdit)
        obj.ID = $("#ID").val();
        obj.AmbulanceCode = $("#AmbulanceCode").val();
        obj.CenterID = $("#CenterID").val();
        obj.StationID = $("#StationID").val();
        obj.ActualCode = $("#ActualCode").combobox('getText');
        obj.AmbulanceNumber = $("#AmbulanceNumber").combobox('getText');
        obj.RepairType = $("#RepairType").combobox("getValue");
        obj.IsChangeRoadCode = $("#IsChangeRoadCode").combobox("getValue");
        obj.InMileage = $("#InMileage").numberbox('getValue');
        obj.OutMileage = $("#OutMileage").numberbox('getValue');
        obj.InOilMass = $("#InOilMass").numberbox('getValue');
        obj.OutOilMass = $("#OutOilMass").numberbox('getValue');
        obj.IsSpareWheel = $("#IsSpareWheel").combobox('getValue');
        obj.IsDrivingLicense = $("#IsDrivingLicense").combobox('getValue');
        obj.SendConfirmedTime = $("#SendConfirmedTime").datetimebox('getText');
        obj.CompletionTime = $("#CompletionTime").datetimebox('getText');
        obj.RepairContent = $("#RepairContent").textbox("getText");
        obj.SendConfirmedPerson = $("#SendConfirmedPerson").textbox("getText");
        obj.RepairPerson = $("#RepairPerson").textbox("getText");
        obj.Inspector = $("#Inspector").textbox("getText");
        obj.Acceptor = $("#Acceptor").textbox("getText");
        obj.Remark = $("#Remark").textbox("getText");
        obj.FillPerson = '@ViewData["name"]';
        obj.FillTime = '@ViewData["time"]';
        return obj;
    }
    //新增入口
    function initAddInfo() {
        //将修改按钮禁用
        $('#btnedit').linkbutton('disable');
        $.GID("btnedit").style.display = "none";
        $('#btnadd').linkbutton('enable');
        $.GID("btnadd").style.display = "block";
        $("#ID").val("");
        $("#AmbulanceCode").val("");
        $("#ActualCode").combobox('setText', "");
        $("#AmbulanceNumber").combobox("setText", "");
        $("#RepairType").combobox("setValue", "");
        $("#IsChangeRoadCode").combobox("setText", "否");
        $("#InMileage").numberbox('clear');
        $("#OutMileage").numberbox('clear');
        $("#InOilMass").numberbox("clear");
        $("#OutOilMass").numberbox("clear");
        $("#IsSpareWheel").combobox("setText", "有");
        $("#IsDrivingLicense").combobox("setText", "有");
        $("#CompletionTime").datetimebox('setValue',"");
        $("#RepairContent").textbox("clear");
        $("#SendConfirmedPerson").textbox("clear");
        $("#RepairPerson").textbox("clear");
        $("#Inspector").textbox("clear");
        $("#Acceptor").textbox("clear");
        $("#Remark").textbox("clear");
        $("#SendConfirmedTime").datetimebox('setValue', "");
        //$.InitControlDateTime("#SendConfirmedTime");
       
    }
    function initUpdateInfo() {
        $('#btnadd').linkbutton('disable');
        $.GID("btnadd").style.display = "none";
        $('#btnedit').linkbutton('enable');
        $.GID("btnedit").style.display = "block";
    }
</script>

<div id="NewRepairMaintainList" class="easyui-dialog" title="整修保养编辑页面" data-options="modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,resizable:false,iconCls:'icon-custom-cWuZiWeiHu'" style="width:730px;height:480px;padding:10px;">
   <input id="ID" type="hidden">
    <input id="AmbulanceCode" type="hidden">
    <input id="CenterID" type="hidden">
    <input id="StationID" type="hidden">
     <table border="0" cellpadding="0" cellspacing="7" style="width: 99%; margin-left: 0px; margin-right: 0px; margin-top: 0px; margin-bottom: 0px">
        <tr>         
            <td style="width: 100px; text-align: right">
                车牌号码：
            </td>
            <td>               
                <input class="easyui-combobox" style="width: 160px" id="ActualCode" data-options="required:true">
            </td>
            <td style="width: 100px; text-align: right">
                车辆编号：
            </td>
            <td>
                <input class="easyui-combobox" style="width: 160px" id="AmbulanceNumber" >
            </td>
        </tr>
        <tr>           
            <td style="width: 110px; text-align: right">
                修理类别：
            </td>
            <td>
                <input class="easyui-combobox" style="width: 160px" id="RepairType" data-options="panelHeight:'auto', editable:false, required:true">
            </td>    
            <td style="width: 100px; text-align: right">
                是否更改路码：
            </td>
            <td>
                <select class="easyui-combobox" style="width: 160px" id="IsChangeRoadCode" data-options="panelHeight:'auto', editable:false">
                    <option value="false">否</option>
                    <option value="true">是</option>
                </select>
            </td>       
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                进厂里程表数：
            </td>
            <td>
                <input class="easyui-numberbox" style="width: 160px" id="InMileage" data-options="required:true,min:0,precision: 2">
            </td>
            <td style="width: 110px; text-align: right">
                进厂油量：
            </td>
            <td>
                <input id="InOilMass" class="easyui-numberbox" style="width: 160px;" data-options="required:true,min:0,precision: 2">
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                出厂里程表数：
            </td>
            <td>
                <input class="easyui-numberbox" style="width: 160px" id="OutMileage" data-options="required:true,min:0,precision: 2">
            </td>
            <td style="width: 110px; text-align: right">
                出厂油量：
            </td>
            <td>
                <input id="OutOilMass" class="easyui-numberbox" style="width: 160px;" data-options="required:true,min:0,precision: 2">
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                备胎：
            </td>
            <td>
                <select class="easyui-combobox" style="width: 160px" id="IsSpareWheel" data-options="panelHeight:'auto', editable:false">                    
                    <option value="true">有</option>
                    <option value="false">无</option>
                </select>
            </td>
            <td style="width: 110px; text-align: right">
                行驶证：
            </td>
            <td>
                <select class="easyui-combobox" style="width: 160px" id="IsDrivingLicense" data-options="panelHeight:'auto', editable:false">
                    <option value="true">有</option>
                    <option value="false">无</option>
                </select>
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                送保日期：
            </td>
            <td>
                <input id="SendConfirmedTime" class="easyui-datetimebox" style="width:160px" data-options="required:true">
            </td>
            <td style="width: 110px; text-align: right">
                竣工日期：
            </td>
            <td>
                <input id="CompletionTime" class="easyui-datetimebox" style="width:160px;" data-options="required:true">
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                整修保养项目：
            </td>
            <td colspan="3">
                <a>
                    <input id="RepairContent" class="easyui-textbox" data-options="multiline:true, required:true" style="width:500px;height:100px">
                </a>
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                送保人：
            </td>
            <td>
                <input id="SendConfirmedPerson" class="easyui-textbox" style="width:160px;" data-options="required:true">
            </td>
            <td style="width: 110px; text-align: right">
                承修人：
            </td>
            <td>
                <input id="RepairPerson" class="easyui-textbox" style="width:160px;" data-options="required:true">
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                车间检验员：
            </td>
            <td>
                <input id="Inspector" class="easyui-textbox" style="width:160px;" data-options="required:true">
            </td>
            <td style="width: 110px; text-align: right">
                分站管理科验收人：
            </td>
            <td>
                <input id="Acceptor" class="easyui-textbox" style="width:160px;" data-options="required:true">
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">备注：</td>
            <td colspan="3">
                <input id="Remark" class="easyui-textbox" data-options="multiline:true" style="width:500px;height:30px">
            </td>
        </tr>
        <tr></tr> 
        <tr></tr> 
        <tr>
            <td colspan="4" style="text-align:center">
                <a href="javascript:void(0)" id="btnedit" class="easyui-linkbutton" style="width:100px;margin: auto" data-options="iconCls:'icon-edit'" onclick="submitEditForm();">确认修改</a>
                <a href="javascript:void(0)" id="btnadd" class="easyui-linkbutton" style="width: 100px;margin: auto" data-options="iconCls:'icon-add'" onclick="submitAddForm();">确认新增</a>
            </td>
        </tr>
    </table>

</div>